package com.zd;


import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.zd.common.GlobalCacheStatic;
import com.zd.dao.sensorData.MonitoringSensorImg;
import com.zd.dao.sensorData.SensorRecords;
import com.zd.dao.sensorData.TaskRecords;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;


@SpringBootTest(classes = BaseDevicePlatApplication.class)
@Slf4j
@RunWith(SpringRunner.class)
public class Code {
    @Resource
    private SensorRecordsMapper sensorRecordsMapper;

    @Resource
    private TaskRecordsMapper receiverRecordsMapper;

    @Resource
    private MonitoringSensorImgMapper monitoringSensorImgMapper;


    @Test
    public void test1() {


        try {
            DynamicDataSourceContextHolder.push(GlobalCacheStatic.ReceiverRecordsBaseSource);
            List<TaskRecords> taskRecordsList = receiverRecordsMapper.selectList(null);
            log.info("taskRecordsList:{}", taskRecordsList);
            try{
                DynamicDataSourceContextHolder.push("sensorSource");
                List<MonitoringSensorImg> sensorImgs = monitoringSensorImgMapper.selectList(null);
                log.info("sensorImgs:{}", sensorImgs);
            }finally {
                DynamicDataSourceContextHolder.poll();
            }
            List<SensorRecords> sensorRecords = sensorRecordsMapper.selectList(null);
            log.info("sensorRecords:{}", sensorRecords);
        } finally {
            DynamicDataSourceContextHolder.poll();
        }

    }
}
